import 'package:flutter/material.dart';
import 'package:study_online/pages/messagePage/home_page.dart';
import 'package:study_online/global/colors.dart';
import 'package:study_online/pages/studyPage/views/StudyPage.dart';

import 'homePage/views/HomeView.dart';
import 'messagePage/MessagePage.dart';
import 'myPage/views/MyPage.dart';

import 'package:flutter/material.dart';

class Tabs extends StatefulWidget {
  Tabs({Key key}) : super(key: key);

  @override
  _TabsState createState() {
    return _TabsState();
  }
}

class _TabsState extends State<Tabs> {
  int _currentIndex = 0;
  PageController _pageController;
  List<Widget> _pageList = [
    HomePage(),
    StudyPage(),
    ChatHomePage(),
    MyPage(),
  ];

  @override
  void initState() {
    super.initState();
    this._pageController = new PageController(initialPage: this._currentIndex);
  }

  @override
  Widget build(BuildContext context) {
    // TODO: implement build
    return Scaffold(
      body: PageView(
        controller: this._pageController,
        children: this._pageList,
      ),
      bottomNavigationBar: BottomNavigationBar(
        backgroundColor: Colors.white,
        currentIndex: _currentIndex,
        onTap: (index) {
          //设置底部图标点击选中
          setState(() {
            this._currentIndex = index;
            this._pageController.jumpToPage(index);
          });
        },
        type: BottomNavigationBarType.fixed,
        //显示多个底部菜单
        fixedColor: AppColors.primary,
        items: [
          BottomNavigationBarItem(
            icon: _currentIndex == 0
                ? Image.asset(
              'assets/img/home_se.png',
              width: 32,
              height: 28,
            )
                : Image.asset(
              'assets/img/home_un.png',
              width: 32,
              height: 28,
            ),
            title: Text('首页'),
          ),
          BottomNavigationBarItem(
            icon: _currentIndex == 1
                ? Image.asset(
              'assets/img/study_se.png',
              width: 32,
              height: 28,
            )
                : Image.asset(
              'assets/img/study_un.png',
              width: 32,
              height: 28,
            ),
            title: Text('学习'),
          ),
          BottomNavigationBarItem(
            icon: _currentIndex == 2
                ? Image.asset(
              'assets/img/message_se.png',
              width: 32,
              height: 28,
            )
                : Image.asset(
              'assets/img/message_un.png',
              width: 32,
              height: 28,
            ),
            title: Text('消息'),
          ),
          BottomNavigationBarItem(
            icon: _currentIndex == 3
                ? Image.asset(
              'assets/img/user_se.png',
              width: 32,
              height: 28,
            )
                : Image.asset(
              'assets/img/user_un.png',
              width: 32,
              height: 28,
            ),
            title: Text('我的'),
          ),
        ],
      ),
    );
  }
}
